package com.yssw.client.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.client.domain.UserServiceLog;
import com.yssw.client.service.IUserServiceLogService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 维修记录Controller
 *
 * @author yssw
 * @date 2023-04-01
 */
@Anonymous
@RestController
@RequestMapping("/client/serviceLog")
public class UserServiceLogController extends BaseController {
    @Autowired
    private IUserServiceLogService userServiceLogService;

    /**
     * 查询维修记录列表
     */
//    @PreAuthorize("@ss.hasPermi('client:serviceLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserServiceLog userServiceLog) {
        startPage();
        List<UserServiceLog> list = userServiceLogService.selectUserServiceLogList(userServiceLog);
        return getDataTable(list);
    }

    /**
     * 导出维修记录列表
     */
//    @PreAuthorize("@ss.hasPermi('client:serviceLog:export')")
    @Log(title = "维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserServiceLog userServiceLog) {
        List<UserServiceLog> list = userServiceLogService.selectUserServiceLogList(userServiceLog);
        ExcelUtil<UserServiceLog> util = new ExcelUtil<UserServiceLog>(UserServiceLog.class);
        util.exportExcel(response, list, "维修记录数据");
    }

    /**
     * 获取维修记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('client:serviceLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(userServiceLogService.selectUserServiceLogById(id));
    }

    /**
     * 新增维修记录
     */
    @PreAuthorize("@ss.hasPermi('client:serviceLog:add')")
    @Log(title = "维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserServiceLog userServiceLog) {
        return toAjax(userServiceLogService.insertUserServiceLog(userServiceLog));
    }

    /**
     * 修改维修记录
     */
    @PreAuthorize("@ss.hasPermi('client:serviceLog:edit')")
    @Log(title = "维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserServiceLog userServiceLog) {
        return toAjax(userServiceLogService.updateUserServiceLog(userServiceLog));
    }

    /**
     * 删除维修记录
     */
    @PreAuthorize("@ss.hasPermi('client:serviceLog:remove')")
    @Log(title = "维修记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userServiceLogService.deleteUserServiceLogByIds(ids));
    }
}
